package com.jiyi.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.jiyi.bean.maintenance.RepairItemBean;
import com.jiyi.bean.maintenance.RepairItemParent;
import com.jiyi.event.CheckUploadEvent;
import com.jiyi.view.DateChooseDialog;
import com.swift.maintenance.R;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zlw
 */
public class RepairItemAdapter extends BaseExpandableListAdapter {
	private Context mContext;
	ArrayList<RepairItemParent> mList = new ArrayList<RepairItemParent>();
	// 保存Spinner选中的position
	private Map<Integer, Integer> isSpin = new HashMap<Integer, Integer>();
	LayoutInflater inflater;
	private final int TYPE_0 = 0;
	private final int TYPE_1 = 1;
	// 显示的类别 1 编辑 2 查看 3 有编辑有查看
	private int type;

	public RepairItemAdapter(Context context,
			ArrayList<RepairItemParent> liveList, int type) {
		this.mContext = context;
		this.mList = liveList;
		inflater = LayoutInflater.from(context);
		this.type = type;

	}

	public void putAllSp() {
		for (int i = 0; i < mList.size(); i++) {
			isSpin.put(i, 0);
		}
	}

	@Override
	public int getGroupCount() {
		return mList.size();
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		int childSize = mList.get(groupPosition).getChildList().size();
		return childSize;
	}

	@Override
	public Object getGroup(int i) {
		return getGroup(i);
	}

	@Override
	public Object getChild(int i, int i1) {
		return getChild(i, i1);
	}

	@Override
	public long getGroupId(int i) {
		return i;
	}

	@Override
	public long getChildId(int i, int i1) {
		return i1;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public View getGroupView(final int position, boolean isExpanded,
			View convertView, ViewGroup viewGroup) {
		GroupHolder groupHolder;
		if (convertView == null) {
			convertView = View.inflate(mContext,
					R.layout.item_repair_item_head, null);
			groupHolder = new GroupHolder(convertView);
			convertView.setTag(groupHolder);
		} else {
			groupHolder = (GroupHolder) convertView.getTag();
		}
		groupHolder.mGroupTitleTv.setText(mList.get(position).getTitle());

		boolean isCheck = false;
		for (int i = 0; i < mList.get(position).getChildList().size(); i++) {
			RepairItemBean detectItem = mList.get(position).getChildList()
					.get(i);
			if (detectItem.getIs_check() == 1) {
				isCheck = true;
				break;
			}
		}

		int isOwnerCheck = 0;
		for (int i = 0; i < mList.get(position).getChildList().size(); i++) {
			RepairItemBean detectItem = mList.get(position).getChildList()
					.get(i);
			if (detectItem.getIs_check() == 1) {
				isOwnerCheck = detectItem.getAuditor_status();
				break;
			}
		}

		Drawable defaultDraw = mContext.getResources().getDrawable(
				R.drawable.detectitem_head_tip);
		defaultDraw.setBounds(0, 0, defaultDraw.getMinimumWidth(),
				defaultDraw.getMinimumHeight());
		if (isCheck) {
			// 根据有异常的项，来对头部进行标志处理
			int tipResId = R.mipmap.icon_owner_check;
			if (isOwnerCheck == 1) {
				tipResId = R.mipmap.icon_owner_checked;
			} else if (isOwnerCheck == 2) {
				tipResId = R.mipmap.icon_owner_uncheck;
			}
			Drawable errorDraw = mContext.getResources().getDrawable(tipResId);
			errorDraw.setBounds(0, 0, errorDraw.getMinimumWidth(),
					errorDraw.getMinimumHeight());
			groupHolder.mGroupTitleTv.setCompoundDrawables(defaultDraw, null,
					errorDraw, null);
		} else {
			groupHolder.mGroupTitleTv.setCompoundDrawables(defaultDraw, null,
					null, null);
		}

		return convertView;
	}

	ArrayAdapter<String> adapter;

	@Override
	public View getChildView(final int groupPosition, final int childPosition,
			boolean b, View convertView, ViewGroup viewGroup) {
		final RepairItemParent repairItemParent = mList.get(groupPosition);
		final RepairItemBean repairItemBean = repairItemParent.getChildList()
				.get(childPosition);
		repairItemBean.setParentPosition(groupPosition);
		repairItemBean.setChildPosition(childPosition);
		int childtype = getChildType(groupPosition, childPosition);
		switch (childtype) {
		case TYPE_0:
			// 编辑状态
			final ChildHolderZore childHolderZore;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_repair_write,
						viewGroup, false);

				childHolderZore = new ChildHolderZore(convertView);
				adapter = new ArrayAdapter<String>(mContext,
						R.layout.item_spinner, mContext.getResources()
								.getStringArray(R.array.equip_state_has_value));
				childHolderZore.state_equip
						.setOnItemSelectedListener(new MyOnOnItemSelectedListener(
								childHolderZore.state_equip));
				childHolderZore.etCreateDate.setKeyListener(null);
				childHolderZore.etCreateDate.setOnClickListener(new CreateDateListener(childHolderZore.etCreateDate));
				convertView.setTag(childHolderZore);
			} else {
				childHolderZore = (ChildHolderZore) convertView.getTag();
			}

			childHolderZore.state_equip.setAdapter(adapter);
			childHolderZore.state_equip.setTag(groupPosition);
			childHolderZore.state_equip.setTag(R.id.tag_item_repairer,
					repairItemBean);

			childHolderZore.etEquipNo.setTag(repairItemBean);
			childHolderZore.etEquipPosition.setTag(repairItemBean);
			childHolderZore.etEquipName.setTag(repairItemBean);
			childHolderZore.etEquipBrand.setTag(repairItemBean);
			childHolderZore.etCreateDate.setTag(repairItemBean);
			childHolderZore.etRemainDate.setTag(repairItemBean);
			childHolderZore.etEquipModel.setTag(repairItemBean);

			childHolderZore.etRecord.setTag(repairItemBean);
			childHolderZore.etPrice.setTag(repairItemBean);
			childHolderZore.etRepairPrice.setTag(repairItemBean);
			childHolderZore.rlMoreProduct.setTag(R.id.tag_item_repairer,
					repairItemBean);
			childHolderZore.etRecord.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					RepairItemBean bean = (RepairItemBean) childHolderZore.etRecord
							.getTag();
					bean.setRecord(s.toString());
					EventBus.getDefault().post(new CheckUploadEvent());
				}
			});

			childHolderZore.etEquipNo.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					RepairItemBean bean = (RepairItemBean) childHolderZore.etEquipNo
							.getTag();
					bean.setBh_code(s.toString());
					EventBus.getDefault().post(new CheckUploadEvent());
				}
			});

			childHolderZore.etEquipPosition
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etEquipPosition
									.getTag();
							bean.setPlace(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.etEquipName
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etEquipName
									.getTag();
							bean.setPro_name(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.etEquipBrand
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etEquipBrand
									.getTag();
							bean.setProduct(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.etEquipBrand
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etEquipBrand
									.getTag();
							bean.setProduct(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.etCreateDate
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etCreateDate
									.getTag();
							bean.setPro_date(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.etRemainDate
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etRemainDate
									.getTag();
							bean.setPro_safe_date(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});
			childHolderZore.etEquipModel
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etEquipModel
									.getTag();
							bean.setPro_type(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.etPrice.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					RepairItemBean bean = (RepairItemBean) childHolderZore.etPrice
							.getTag();
					bean.setPrice(s.toString());
					EventBus.getDefault().post(new CheckUploadEvent());
				}
			});

			childHolderZore.etRepairPrice
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							RepairItemBean bean = (RepairItemBean) childHolderZore.etRepairPrice
									.getTag();
							bean.setAmount(s.toString());
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			childHolderZore.tvRepairFirstEquip.setText(repairItemBean
					.getInspection_name());
			childHolderZore.tvRepairSecondEquip.setText(repairItemBean
					.getEquipment_name());
			childHolderZore.tvRepairEquipItem.setText(repairItemBean
					.getBad_name());
			childHolderZore.etEquipNo.setText(repairItemBean.getBh_code());
			childHolderZore.etEquipPosition.setText(repairItemBean.getPlace());
			childHolderZore.etRecord.setText(repairItemBean.getRecord());
			childHolderZore.etEquipName.setText(repairItemBean.getPro_name());
			childHolderZore.etEquipBrand.setText(repairItemBean.getProduct());
			childHolderZore.etCreateDate.setText(repairItemBean.getPro_date());
			childHolderZore.etRemainDate.setText(repairItemBean
					.getPro_safe_date());
			childHolderZore.etEquipModel.setText(repairItemBean.getPro_type());
			childHolderZore.etPrice.setText(repairItemBean.getPrice());
			childHolderZore.etRepairPrice.setText(repairItemBean.getAmount());

			childHolderZore.state_equip.setSelection(isSpin.get(groupPosition),
					true);

			refreshPayerAdapter(
					(ArrayAdapter) childHolderZore.state_payer.getTag(),
					childHolderZore.state_payer);
			childHolderZore.state_payer
					.setOnItemSelectedListener(new OnItemSelectedListener() {

						@Override
						public void onItemSelected(AdapterView<?> parent,
								View view, int position, long id) {
							mList.get(groupPosition).getChildList()
									.get(childPosition).setPayer(position);
							EventBus.getDefault().post(new CheckUploadEvent());
						}

						@Override
						public void onNothingSelected(AdapterView<?> parent) {

						}
					});
			childHolderZore.state_payer.setSelection(repairItemBean.getPayer());

			childHolderZore.rgCheck
					.setOnCheckedChangeListener(new OnCheckedChangeListener() {

						@Override
						public void onCheckedChanged(RadioGroup group,
								int checkedId) {
							if (checkedId == R.id.rbNoCheck) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setIs_check(0);
							} else {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setIs_check(1);
							}
							notifyDataSetChanged();
							EventBus.getDefault().post(new CheckUploadEvent());
						}
					});

			if (repairItemBean.getIs_check() == 0) {
				childHolderZore.rgCheck.check(R.id.rbNoCheck);
			} else {
				childHolderZore.rgCheck.check(R.id.rbNeedCheck);
			}

			childHolderZore.rlMoreProduct
					.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							if (v.getTag() == null) {
								childHolderZore.llProduct
										.setVisibility(View.VISIBLE);
								v.setTag("extend");
								RepairItemBean bean = (RepairItemBean) childHolderZore.rlMoreProduct
										.getTag(R.id.tag_item_repairer);
								bean.setShowMore(true);
							} else {
								childHolderZore.llProduct
										.setVisibility(View.GONE);
								v.setTag(null);
								RepairItemBean bean = (RepairItemBean) childHolderZore.rlMoreProduct
										.getTag(R.id.tag_item_repairer);
								bean.setShowMore(false);
							}

						}
					});

			if (repairItemBean.isShowMore()) {
				childHolderZore.llProduct.setVisibility(View.VISIBLE);
				childHolderZore.rlMoreProduct.setTag("extend");
			} else {
				childHolderZore.llProduct.setVisibility(View.GONE);
				childHolderZore.rlMoreProduct.setTag(null);
			}

			break;
		case TYPE_1:
			// 查看状态
			final ChildHolderOne childHolderOne;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_repair_read,
						viewGroup, false);
				childHolderOne = new ChildHolderOne(convertView);
				convertView.setTag(childHolderOne);
			} else {
				childHolderOne = (ChildHolderOne) convertView.getTag();
			}

			childHolderOne.tvRepairFirstEquip.setText(repairItemBean
					.getInspection_name());
			childHolderOne.tvRepairSecondEquip.setText(repairItemBean
					.getEquipment_name());
			childHolderOne.tvRepairEquipItem.setText(repairItemBean
					.getBad_name());
			childHolderOne.tvEquipNo.setText(repairItemBean.getBh_code());
			childHolderOne.tvEquipPosition.setText(repairItemBean.getPlace());
			childHolderOne.tvEquipRecord.setText(repairItemBean.getRecord());
			childHolderOne.tvEquipName.setText(repairItemBean.getPro_name());
			childHolderOne.tvEquipBrand.setText(repairItemBean.getProduct());
			childHolderOne.tvCreateDate.setText(repairItemBean.getPro_date());
			childHolderOne.tvRemainDate.setText(repairItemBean
					.getPro_safe_date());
			childHolderOne.tvEquipModel.setText(repairItemBean.getPro_type());
			childHolderOne.tvEquipPrice.setText(repairItemBean.getPrice());
			childHolderOne.tvRepairPrice.setText(repairItemBean.getAmount());
			childHolderOne.tvPayer
					.setText(repairItemBean.getPayer() == 0 ? "业主" : "维保单位");

			childHolderOne.tvDisAgree.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					mList.get(groupPosition).getChildList().get(childPosition)
							.setAuditor_status(2);
					EventBus.getDefault().post(new CheckUploadEvent());
					notifyDataSetChanged();
				}
			});
			childHolderOne.tvAgree.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					mList.get(groupPosition).getChildList().get(childPosition)
							.setAuditor_status(1);
					EventBus.getDefault().post(new CheckUploadEvent());
					notifyDataSetChanged();
				}
			});

			if (type == 5) {
				if (repairItemBean.getIs_check() == 0) {
					childHolderOne.llShowOwnerCheck.setVisibility(View.VISIBLE);
					childHolderOne.llDoOwnerCheck.setVisibility(View.GONE);
					childHolderOne.tvCheck
							.setText(repairItemBean.getIs_check() == 0 ? "不需要审核"
									: "需要审核");
				} else {
					if (repairItemBean.getAuditor_status() == 0) {
						childHolderOne.llShowOwnerCheck
								.setVisibility(View.GONE);
						childHolderOne.llDoOwnerCheck
								.setVisibility(View.VISIBLE);
					} else {
						childHolderOne.llShowOwnerCheck
								.setVisibility(View.VISIBLE);
						childHolderOne.llDoOwnerCheck.setVisibility(View.GONE);
						childHolderOne.tvCheck.setText(repairItemBean
								.getAuditor_status() == 1 ? "已同意" : "已否决");
					}
				}

			} else {
				childHolderOne.llShowOwnerCheck.setVisibility(View.VISIBLE);
				childHolderOne.llDoOwnerCheck.setVisibility(View.GONE);
				childHolderOne.tvCheck
						.setText(repairItemBean.getIs_check() == 0 ? "不需要审核"
								: "需要审核");
			}

			// 0新增，1维修，2更换,3保养，4保修,
			if (repairItemBean.getEquip_status() == 0) {
				childHolderOne.tvEquipStatus.setText("新增");
			} else if (repairItemBean.getEquip_status() == 1) {
				childHolderOne.tvEquipStatus.setText("维修");
			} else if (repairItemBean.getEquip_status() == 2) {
				childHolderOne.tvEquipStatus.setText("更换");
			} else if (repairItemBean.getEquip_status() == 3) {
				childHolderOne.tvEquipStatus.setText("保养");
			} else {
				childHolderOne.tvEquipStatus.setText("保修");
			}

			childHolderOne.rlMoreProduct
					.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							if (v.getTag() == null) {
								childHolderOne.llProduct
										.setVisibility(View.VISIBLE);
								v.setTag("extend");
							} else {
								childHolderOne.llProduct
										.setVisibility(View.GONE);
								v.setTag(null);
							}

						}
					});

			break;
		}

		return convertView;

	}

	@Override
	public boolean isChildSelectable(int i, int i1) {
		return true;
	}

	class GroupHolder {
		TextView mGroupTitleTv;
		TextView tvMore;

		public GroupHolder(View view) {
			mGroupTitleTv = (TextView) view.findViewById(R.id.groupTitle);
			tvMore = (TextView) view.findViewById(R.id.tvMore);
		}
	}

	class ChildHolderZore {
		TextView tvRepairFirstEquip;
		TextView tvRepairSecondEquip;
		TextView tvRepairEquipItem;
		EditText etEquipNo;
		EditText etEquipPosition;
		EditText etRecord;
		EditText etEquipName;
		EditText etEquipBrand;
		EditText etCreateDate;
		EditText etRemainDate;
		EditText etEquipModel;
		Spinner state_equip;
		EditText etPrice;
		EditText etRepairPrice;
		Spinner state_payer;
		RadioGroup rgCheck;
		RelativeLayout rlMoreProduct;
		LinearLayout llProduct;

		public ChildHolderZore(View convertView) {
			tvRepairFirstEquip = (TextView) convertView
					.findViewById(R.id.tvRepairFirstEquip);
			tvRepairSecondEquip = (TextView) convertView
					.findViewById(R.id.tvRepairSecondEquip);
			tvRepairEquipItem = (TextView) convertView
					.findViewById(R.id.tvRepairEquipItem);
			etEquipNo = (EditText) convertView.findViewById(R.id.etEquipNo);
			etEquipPosition = (EditText) convertView
					.findViewById(R.id.etEquipPosition);

			etRecord = (EditText) convertView.findViewById(R.id.etRecord);
			etEquipName = (EditText) convertView.findViewById(R.id.etEquipName);
			etEquipBrand = (EditText) convertView
					.findViewById(R.id.etEquipBrand);
			etCreateDate = (EditText) convertView
					.findViewById(R.id.etCreateDate);
			etRemainDate = (EditText) convertView
					.findViewById(R.id.etRemainDate);
			etEquipModel = (EditText) convertView
					.findViewById(R.id.etEquipModel);
			state_equip = (Spinner) convertView.findViewById(R.id.state_equip);
			etPrice = (EditText) convertView.findViewById(R.id.etPrice);
			etRepairPrice = (EditText) convertView
					.findViewById(R.id.etRepairPrice);
			state_payer = (Spinner) convertView.findViewById(R.id.state_payer);
			rgCheck = (RadioGroup) convertView.findViewById(R.id.rgCheck);
			rlMoreProduct = (RelativeLayout) convertView
					.findViewById(R.id.rlMoreProduct);
			llProduct = (LinearLayout) convertView.findViewById(R.id.llProduct);
		}
	}

	class ChildHolderOne {
		TextView tvRepairFirstEquip;
		TextView tvRepairSecondEquip;
		TextView tvRepairEquipItem;
		TextView tvEquipNo;
		TextView tvEquipPosition;
		TextView tvEquipRecord;
		TextView tvEquipName;
		TextView tvEquipBrand;
		TextView tvCreateDate;
		TextView tvRemainDate;
		TextView tvEquipModel;
		TextView tvEquipStatus;
		TextView tvEquipPrice;
		TextView tvRepairPrice;
		TextView tvPayer;
		TextView tvCheck;
		RelativeLayout rlMoreProduct;
		LinearLayout llProduct;
		LinearLayout llDoOwnerCheck;
		LinearLayout llShowOwnerCheck;
		TextView tvDisAgree;
		TextView tvAgree;

		public ChildHolderOne(View convertView) {
			tvRepairFirstEquip = (TextView) convertView
					.findViewById(R.id.tvRepairFirstEquip);
			tvRepairSecondEquip = (TextView) convertView
					.findViewById(R.id.tvRepairSecondEquip);
			tvRepairEquipItem = (TextView) convertView
					.findViewById(R.id.tvRepairEquipItem);
			tvEquipNo = (TextView) convertView.findViewById(R.id.tvEquipNo);
			tvEquipPosition = (TextView) convertView
					.findViewById(R.id.tvEquipPosition);

			tvEquipRecord = (TextView) convertView
					.findViewById(R.id.tvEquipRecord);
			tvEquipName = (TextView) convertView.findViewById(R.id.tvEquipName);
			tvEquipBrand = (TextView) convertView
					.findViewById(R.id.tvEquipBrand);
			tvCreateDate = (TextView) convertView
					.findViewById(R.id.tvCreateDate);
			tvRemainDate = (TextView) convertView
					.findViewById(R.id.tvRemainDate);
			tvEquipModel = (TextView) convertView
					.findViewById(R.id.tvEquipModel);
			tvEquipStatus = (TextView) convertView
					.findViewById(R.id.tvEquipStatus);
			tvEquipPrice = (TextView) convertView
					.findViewById(R.id.tvEquipPrice);
			tvRepairPrice = (TextView) convertView
					.findViewById(R.id.tvRepairPrice);
			tvPayer = (TextView) convertView.findViewById(R.id.tvPayer);
			tvCheck = (TextView) convertView.findViewById(R.id.tvCheck);
			tvDisAgree = (TextView) convertView.findViewById(R.id.tvDisAgree);
			tvAgree = (TextView) convertView.findViewById(R.id.tvAgree);
			rlMoreProduct = (RelativeLayout) convertView
					.findViewById(R.id.rlMoreProduct);
			llProduct = (LinearLayout) convertView.findViewById(R.id.llProduct);
			llDoOwnerCheck = (LinearLayout) convertView
					.findViewById(R.id.llDoOwnerCheck);
			llShowOwnerCheck = (LinearLayout) convertView
					.findViewById(R.id.llShowOwnerCheck);
		}
	}

	@Override
	public int getChildType(int groupPosition, int childPosition) {
		if (type == 1) {
			// 编辑
			return TYPE_0;
		} else if (type == 2) {
			// 查看
			return TYPE_1;
		} else if (type == 3) {
			// 可编辑可查看 auditor_status 0待同意 1同意 2不同意
			int auditor_status = mList.get(groupPosition).getChildList()
					.get(childPosition).getAuditor_status();
			// 只有在业主不同意的情况才显示可编辑
			if (auditor_status == 2) {
				return TYPE_0;
			}
			return TYPE_1;
		} else {
			return TYPE_1;
		}
	}

	@Override
	public int getChildTypeCount() {
		return 4;
	}

	public ArrayList<RepairItemParent> getmList() {
		return mList;
	}

	private void refreshPayerAdapter(ArrayAdapter adapter, final Spinner spinner) {
		if (adapter == null) {
			ArrayAdapter<String> statePayerAdapter = new ArrayAdapter<String>(
					mContext, R.layout.item_spinner, mContext.getResources()
							.getStringArray(R.array.payer_state));
			spinner.setAdapter(statePayerAdapter);
			spinner.setTag(statePayerAdapter);
		} else {
			adapter.notifyDataSetChanged();
		}
	}

	class MyOnOnItemSelectedListener implements
			OnItemSelectedListener {
		Spinner sp_test;

		public MyOnOnItemSelectedListener(Spinner sp_test) {
			this.sp_test = sp_test;
		}

		@Override
		public void onItemSelected(AdapterView<?> parent, View view,
				int position, long id) {
			RepairItemBean bean = (RepairItemBean) sp_test
					.getTag(R.id.tag_item_repairer);
			bean.setEquip_status(position);
			int group = (Integer) sp_test.getTag();
			isSpin.put(group, position);
			EventBus.getDefault().post(new CheckUploadEvent());
		}

		@Override
		public void onNothingSelected(AdapterView<?> parent) {

		}
	}

	class CreateDateListener implements OnClickListener {
		EditText etCreateDate;
		DateChooseDialog.Builder builder;
		public CreateDateListener(EditText etCreateDate) {
			this.etCreateDate = etCreateDate;
		}

		@Override
		public void onClick(View v) {
			//生产日期
			builder = new DateChooseDialog.Builder(etCreateDate.getContext(),etCreateDate.getText().toString());
			builder.setTitle("选择日期");  
			builder.setTextView(etCreateDate);
			builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {  
				public void onClick(DialogInterface dialog, int which) {  
					dialog.dismiss();  						
				}
			});
			
			builder.setNegativeButton("取消",  
					new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {  
					dialog.dismiss();  
				}  
			});  
			builder.create().show();
		}
	}
	
}